package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.request.PbRequest;
import com.ytjj.qmyx.admin.service.PbService;
import com.ytjj.qmyx.mall.model.Pb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 内容鉴权
 */
@RestController
@RequestMapping("/pb")
public class PbController {
    @Autowired(required = false)
    private PbService pbService;

    /**
     * 分页查询所有鉴权
     * @param pbRequest
     * @return
     */
    @PostMapping("/list")
    public CommonResult list (@RequestBody PbRequest pbRequest){
        CommonPage<Pb> pageList = pbService.selectList(pbRequest);
        return CommonResult.success(pageList);
    }

    /**
     * 根据ID查询
     * @param Pbid
     * @return
     */
    @PostMapping("selectById")
    public CommonResult selectByPbId(@RequestParam Integer Pbid ){
        Pb pb = pbService.selectByPbId(Pbid);
        return CommonResult.success(pb);
    }

    /**
     * 编译内容鉴权
     */
    @PostMapping("update")
    public CommonResult update(@RequestBody Pb pb){
        Integer count = pbService.update(pb);
        if (count>0){
            return CommonResult.success(count);
        }
            return CommonResult.failed();
    }

    /**
     * 新增
     */
    @PostMapping("add")
    public CommonResult add(@RequestBody Pb pb){
        Integer count = pbService.add(pb);
        if (count>0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
    /**
     * 删除
     */
    @DeleteMapping("delete")
    public CommonResult delete(@RequestBody PbRequest pbRequest){
        Integer count = pbService.delete(pbRequest);
        if (count>0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
}
